import argparse
from osgeo.gdal import DEMProcessing, Open


class Aspect:
    def __init__(self, args, **kwargs):
        self.input_path = None
        self.output_path = None
        if args is not None:
            for key in args.__dict__:
                self[key] = args.__dict__[key]
        for key in kwargs.keys():
            self[key] = kwargs[key]

    def __getitem__(self, item):
        return self.__dict__[item]

    def __setitem__(self, key, value):
        self.__dict__[key] = value

    def __str__(self):
        return f"input={self.input_path},output={self.output_path}"

    def run(self):
        """
        执行坡向计算。

        :return:
        """
        input_dem = Open(self.input_path)  # 加载输入数据
        DEMProcessing(destName=self.output_path, srcDS=input_dem, processing="aspect")  # 进行坡度计算
        # 保存输出结果


if __name__ == '__main__':
    # 接收控制台传入参数
    parser = argparse.ArgumentParser(description='classification parameters')
    parser.add_argument('input_path', type=str, help='input file path')
    parser.add_argument('output_path', type=str, help='output file path')
    args = parser.parse_args()
    # print(args.__dict__)
    asp = Aspect(args=args)
    asp.run()
    # print(slp)
